<?php 

/**
 * 
 * The Content class represents a single piece of content inside of the jankCMS
 * system. This content contains information such as the title, date, author, 
 * and main content of the object. It also contains methods to modify this information.
 * 
 * @author Rick Hutcheson
 *
 */
class Content {
	private $id 			= NULL;
	private $type 			= NULL;
	private $title 			= NULL;
	private $author 		= NULL;
	private $date 			= NULL;
	private $content 		= NULL;
	private $comments 		= NULL;
	private $description 	= NULL;
	private $attachments 	= NULL;
	private $tags 			= NULL;
	
	
	/**
	 * 
	 * Creates a new Content with only its required information; that is, 
	 * the title, author, date, and main content of the Content.
	 * 
	 * @param string $type
	 * 	The type of the content.
	 * @param string $title
	 * 	The title of the content.
	 * @param User $author
	 * 	The author of the Content. 
	 * @param DateTime $date
	 * 	The creation date of this Content.
	 * @param string $content
	 * 	The main content of the content obejct. This is the text and content shown 
	 * 	when the content is displayed fully. 
	 * 
	 * @throws MissingDateException
	 * 	A MissingDateException is thrown if a date is not specified.
	 */
	public function __construct($type, $id, $title, $author, $date, $content) {
		$this->type = $type;
		$this->id = $id;
		$this->title = $title;
		$this->author = $author;
		$this->date = DateTime::createFromFormat('Y-m-d', $date);
		$this->content = $content;
	}
	
	
	/**
	*
	* Sets the type of the Content to the specified string.
	*
	* @param string $type
	* 	The type to be assigned to this Content.
	*/
	public function setType($type) {
	$this->type = $type;
	}
	
	
	/**
	 * 
	 * Sets the title of the Content to the specified string.
	 * 
	 * @param string $title
	 * 	The title to be given to this Content.
	 */
	public function setTitle($title) {
		$this->title = $title;
	}	
	
	/**
	 * 
	 * Sets the author of this Content to the given user.
	 * @param User $author
	 * 	The user to be assigned to this Content.
	 */
	public function setAuthor($author) {
		$this->author = $author->getUsername();
	}
	
	/**
	 * 
	 * Sets the date of this Content to the given date.
	 * @param DateTime $date
	 * 	The date to be assigned to this Content.
	 */
	public function setDate($date) {
		$this->date = DateTime::createFromFormat('Y-m-d', $date);
	}
	
	/**
	 * 
	 * Sets the content of this Content to the given string.
	 * @param string $content
	 * 	The content to assign to this Content.
	 */
	public function setContent($content) {
		$this->content = $content;
	}
	
	/**
	 * 
	 * Sets the comments of this Content to the given string array
	 * @param array $comments
	 * 	The array of the comments to assign to this content.
	 */
	public function setComments(array $comments) {
		$this->comments = $comments;
	}
	
	/**
	 * 
	 * Sets the tags of this Content to the given string array.
	 * @param array $tags
	 * 	The array of the tags (as strings) to assign to this content.
	 */
	public function setTags(array $tags) {
		$this->tags = $tags;
	}
	
	/**
	 * 
	 * Sets the attachments of this Content to the given file array.
	 * @param array $attachments
	 * 	The array of the file handles to assign to this content.
	 */
	public function setAttachments(array $attachments) {
		$this->attachments = $attachments;
	}
	
	/**
	*
	* Sets the description of this Content to the given string.
	* @param string $description
	* 	The description to assign to this content.
	*/	
	public function setDescription($description) {
		$this->description = $description;
	}
	
	/**
	*
	* Returns the id of this Content.
	*
	* @return The id of the content.
	*/
	public function getID() {
		return $this->id;
	}
	
	/**
	*
	* Returns the type of this Content.
	*
	* @return The type of the content.
	*/
	public function getType() {
		return $this->type;
	}
	
	/**
	 * 
	 * Returns the title of this Content.
	 * 
	 * @return The title of the content.
	 */
	public function getTitle() {
		return $this->title;
	}
	
	/**
	*
	* Returns the author of this Content.
	*
	* @return The author of the content.
	*/
	public function getAuthor() {
		return $this->author;
	}
	
	/**
	*
	* Returns the date of this Content.
	*
	* @return The date of the content.
	*/
	public function getDate() {
		return $this->date;
	}
	
	
	/**
	*
	* Returns the content of this Content.
	*
	* @return The content of the content.
	*/
	public function getContent() {
		return $this->content;
	}
	
	/**
	*
	* Returns the comments of this Content.
	*
	* @return The comments of the content.
	*/
	public function getComments() {
		return $this->comments;
	}
	
	/**
	*
	* Returns the tags of this Content.
	*
	* @return The tags of the content.
	*/
	public function getTags() {
		return $this->tags;
	}
	
	/**
	*
	* Returns the attachments of this Content.
	*
	* @return The attachments of the content.
	*/
	public function getAttachments() {
		return $this->attachments;
	}

	/**
	 * 
	 * Returns the description of this Content.
	 * 
	 * @return The description of the content.
	 */
	 public function getDescription() {
	 	return $this->description;
	 }
	 
	 public function getTagsAsString() {
	 	$tags = $this->getTags();
	 	$tagString = "";
	 	for ($i = 0; $i < count($tags); $i++) {
	 		if ($i == (count($tags) - 1)) {
	 			$tagString .= $tags[$i];
	 		} else {
	 			$tagString .= $tags[$i] . ", ";
	 
	 		}
	 	}
	 	return $tagString;
	 }
}